home *** CD-ROM | disk | FTP | other *** search
- /*
- * messages.c - help with formatting and display of messages
- */
- #include "RevRdist.h"
- #include <TransSkelProto.h>
- #include <TransDisplayProto.h>
-
- extern StringPtr syserrlist (OSErr);
-
-
- /*
- *=========================================================================
- * dispIndStr (w, idx, str, p0, p1, p2, p3) - display STR# with params
- * entry: w = TransDisplay window to display text in
- * idx = string index in STR# resource
- * str = STR# resource id
- * p0, p1, p2, p3 = strings to substitute into text, if fewer
- * than 4 strings are needed, end list early with nil
- *=========================================================================
- */
-
- void
- dispIndStr (w, idx, str, p0, p1, p2, p3)
- WindowPtr w;
- Integer idx;
- Integer str;
- StringPtr p0, p1, p2, p3;
- {
- Handle h;
- WindowPtr oldw;
- Longint offset;
- Size len;
-
- if (w == nil)
- return;
- h = NewHandle ((Size) 256);
- if (h == nil)
- return;
- GetDWindow (&oldw); /* remember current window */
- if (w != oldw)
- SetDWindow (w); /* and switch to new window */
- HLock (h);
- GetIndString ((StringPtr) (*h), str, idx);
- if (**h == 0)
- goto eexit;
- HUnlock (h);
- SetHandleSize (h, (Size) (**h) + 1);
- /*
- * For each parameter up to a nil ptr, use Munger to insert it in
- * the text.
- */
- offset = 1;
- if (!p0)
- goto done;
- offset = Munger (h, offset, (Ptr) "^0", 2, &p0[1], (long) p0[0]);
- if (offset < 0)
- goto done;
- if (!p1)
- goto done;
- offset = Munger (h, offset, (Ptr) "^1", 2, &p1[1], (long) p1[0]);
- if (offset < 0)
- goto done;
- if (!p2)
- goto done;
- offset = Munger (h, offset, (Ptr) "^2", 2, &p2[1], (long) p2[0]);
- if (offset < 0)
- goto done;
- if (!p3)
- goto done;
- offset = Munger (h, offset, (Ptr) "^3", 2, &p3[1], (long) p3[0]);
-
- done:
- HLock (h);
- if (w == ActivityWind && Depth > 0)
- DisplayText(" ", (Longint)(Depth <= 10 ? Depth : 10));
- len = GetHandleSize (h) - 1;
- DisplayText ((*h)+1, len);
- DisplayLn ();
- if (w == ActivityWind)
- {
- if (len > 255)
- len = 255;
- **h = len;
- statMsg (*(StringHandle)h);
- }
- eexit:
- HUnlock (h);
- DisposHandle (h);
- if (w != oldw)
- SetDWindow (oldw);
- }
-
-
- /*
- *=========================================================================
- * notice (idx, p0, p1, p2, p3) - write msg to activity window
- * entry: idx = index (L_xxx) of message text
- * p0, ... = strings to substitute in text
- *=========================================================================
- */
- void
- notice (idx, p0, p1, p2, p3)
- Integer idx;
- StringPtr p0, p1, p2, p3;
- {
- int i;
- StringPtr ap0, ap1, ap2, ap3;
- unsigned char cbuf[20];
-
- i = (ap0=p0) ? ((ap1=p1) ? ((ap2=p2) ? ((ap3=p3) ? 4: 3) : 2) : 1) : 0;
- switch (i)
- {
- case 0: ap0 = Clue0;
- case 1: ap1 = Clue1;
- case 2: ap2 = Clue2;
- case 3: ap3 = Clue3;
- }
- if (idx == L_SYS && p2 == nil)
- ap2 = syserrlist (ClueID);
- if (idx == L_FILE && (i < 1 || p1 == nil))
- ap1 = syserrlist (ClueID);
- dispIndStr (ActivityWind, idx, LST_STR, ap0, ap1, ap2, ap3);
- }
-
-
- /*
- *=========================================================================
- * panic (f, idx, p0, p1, p2) - display panic alert
- * entry: f = false if user can choose to ignore error
- * idx = index in ERR_STR of text
- * p0, p1, p2 = substitutable text
- * exit: Quit set true if user selects CANCEL
- *=========================================================================
- */
-
- void
- panic (f, idx, p0, p1, p2)
- Boolean f;
- Integer idx;
- StringPtr p0, p1, p2;
- {
- Integer i;
- Integer oldresfile;
- StringPtr ap0, ap1, ap2, ap3;
- Str255 buf;
- unsigned char cbuf[20];
-
- i = (ap0=p0) ? ((ap1=p1) ? ((ap2=p2) ? 3 : 2) : 1) : 0;
- switch (i)
- {
- case 0: ap0 = Clue0;
- case 1: ap1 = Clue1;
- case 2: ap2 = Clue2;
- }
- if (idx == E_SYS && (i < 2 || p2 == nil))
- ap2 = syserrlist (ClueID);
- if (idx == E_FILE && (i < 1 || p1 == nil))
- ap1 = syserrlist (ClueID);
- oldresfile = CurResFile ();
- UseResFile (Ap_refNum);
- GetIndString (buf, ERR_STR, idx);
- ParamText (ap0, ap1, ap2, buf);
- if (f)
- i = StopAlert (RSRC_BASE+ALERT_PANIC, nil);
- else
- i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
- if (f || i == ALRT_CANCEL)
- Quit = true;
- UseResFile (oldresfile);
- }
-
- /*
- *=========================================================================
- * warning (idx, p0, p1, p2, p3) - display warning message
- * in the error and activity windows
- * and produce an alert unless we are the startup application
- * entry: idx = index in ERR_STR STR# of text
- * p0, p1, p2 = substitutable text
- *=========================================================================
- */
-
- void
- warning (idx, p0, p1, p2)
- Integer idx;
- StringPtr p0, p1, p2;
- {
- Integer i;
- static oldidx = -1;
- Integer oldresfile;
- StringPtr ap0, ap1, ap2, ap3;
- Str255 buf;
- unsigned char cbuf[20];
-
- i = (ap0=p0) ? ((ap1=p1) ? ((ap2=p2) ? 3 : 2) : 1) : 0;
- switch (i)
- {
- case 0: ap0 = Clue0;
- case 1: ap1 = Clue1;
- case 2: ap2 = Clue2;
- }
- if (idx == E_SYS && (i < 2 || p2 == nil))
- ap2 = syserrlist (ClueID);
- if (idx == E_FILE && (i < 1 || p1 == nil))
- ap1 = syserrlist (ClueID);
- oldresfile = CurResFile ();
- UseResFile (Ap_refNum);
- dispIndStr (ActivityWind, idx, ERR_STR, ap0, ap1, ap2, nil);
- dispIndStr (ErrorWind, idx, ERR_STR, ap0, ap1, ap2, nil);
- ErrorMsgs++;
- if ( !(Flags & DB_STARTUP) && idx != oldidx)
- {
- GetIndString (buf, ERR_STR, idx);
- ParamText (ap0, ap1, ap2, buf);
- i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
- if (i == ALRT_CANCEL)
- Quit = true;
- }
- if (Flags & DB_STARTUP)
- Quit = true;
- oldidx = idx;
- UseResFile (oldresfile);
- }